import java.util.Stack;

public class Test {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        //遍历获取每一个元素
        for(String s: tokens){
            //判断元素是否是运算符
            if(isOpera(s)){
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(s){
                    case "+":
                        stack.push(num1+num2);
                        break;
                    case "-":
                        stack.push(num1-num2);
                        break;
                    case "*":
                        stack.push(num1*num2);
                        break;
                    case "/":
                        stack.push(num1/num2);
                        break;
                }

            }else{
                stack.push(Integer.parseInt(s));

            }
        }
        return stack.pop();

    }

    public boolean isOpera(String s){
        if(s.equals("+") || s.equals("-")  || s.equals("*") || s.equals("/")){
            return true;
        }
        return false;
    }
}
